package com.zdy.gaoji;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by 逸足天涯
 * on 3/10/2020.
 */
//回顾线程总结
public class ThreadNew {
    public static void main(String[] args) {
        new Thread1().start();
        new Thread(new Thread2()).start();
        FutureTask<Integer> futureTask = new FutureTask(new Thread3());
        new Thread(futureTask).start();

        try {
            Integer integer = futureTask.get();
            System.out.println(integer);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
//方式一 继承Thread 类
class Thread1 extends Thread{
    @Override
    public void run() {
        System.out.println("继承Thread线程创建");
    }
}

//方式二 继承Thread 类
class Thread2 implements Runnable{
    @Override
    public void run() {
        System.out.println("实现Runnable 接口线程创建");
    }
}

//方式三 实现Callalbe 接口
class Thread3 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("继承Callable 方法");
        return 100;
    }
}

